﻿using System;
using System.Web.UI.WebControls;
using Library.WebControls.Ds;

namespace Library.WebControls.SimpleGridView {
	public class ExportingContentArgs : ExportArgs {
		internal ExportingContentArgs(SpGridView gridView, PlaceHolder content, Table table)
			: base(gridView, content, table) {
		}

		public bool Handled { get; set; }
		internal DataSourceWrapper.DataItemWraper ItemWrapper { get; set; }
		public object DataItem { get { return ItemWrapper.OriginalItem; } }
		public TableRow DefaultContentRow(bool includeValue) {
			var content = new TableRow();
			foreach (var column in Grid.VisibleColumns) {
				var cell = new TableCell();
				column.ContentExportStyle.CopyStyleToCell(cell);
				if (includeValue) {
					if (!String.IsNullOrEmpty(column.FieldName)) {
						var value = ItemWrapper.GetPropertyValue(column.FieldName);
						cell.Text = column.InternalGetText(value, ItemWrapper.OriginalItem);
					}
				}
				content.Cells.Add(cell);
			}
			return content;
		}
	}
}
